<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">查询质检报表</h3></div>
            <div class="panel-body">

                <div class="container-fluid">
                    <form action="__URL__/checked_orders_report" method="get">
                        <div class="col-sm-12 col-md-6  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">质检时间</span>
                                <input class="form-control form-datetime" type="text" name="create_time_from"
                                       id="create_time_from"
                                       value="<?php echo isset($_GET['create_time_from'])?$_GET['create_time_from']:''; ?>"
                                       style="cursor:pointer;" readonly>
                                <span class="input-group-addon"><span class="icon-calendar"></span></span>
                                <input class="form-control form-datetime" type="text" name="create_time_to"
                                       id="create_time_to"
                                       value="<?php echo isset($_GET['create_time_to'])?$_GET['create_time_to']:''; ?>"
                                       style="cursor:pointer;" readonly>

                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">采购单号</span>
                                <input type="text" name="purchaseorder_id" class="form-control" id="purchaseorder_id"
                                       value="<?php echo isset($_GET['purchaseorder_id'])?$_GET['purchaseorder_id']:''; ?>"
                                       onkeyup="this.value=trim(this.value)">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-1  add-space">
                            <div class="input-group input-group-md">
                                <select type="text" name="print_status" id="print_status" class="form-control">
                                    <option value="1"
                                    <?php if(isset($_GET['print_status']) and '1' == $_GET['print_status']) echo 'selected'; ?>
                                    >已打印</option>
                                    <option value="-1"
                                    <?php if(isset($_GET['print_status']) and '-1' == $_GET['print_status']) echo 'selected'; ?>
                                    >未打印</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-2 add-space">
                            <input class="btn btn-primary" type="submit" value="查询">
                        </div>
                    </form>

                </div>
                <div class="clearfix"></div>
                <hr>
                <div class="fixed-table-toolbar">
                    <h3><input id="checkAll" type="checkbox">
                        <button type="button" class="btn  btn-info a" onclick="print_quality_reports()">选中打印
                        </button>
                    </h3>

                </div>
                <?php foreach($data['result'] as $_data) { ?>
                <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th width="20"></th>
                        <th>站点</th>
                        <th>采购单号</th>
                        <th>质检单号</th>
                        <th>SKU</th>
                        <th>采购名称</th>
                        <th>报关品名</th>
                        <th>所属仓库</th>
                        <th>质检时间</th>
                        <th>质检员</th>
                        <th>状态</th>
                        <th>凭证单号</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($_data as $_data2) { ?>
                    <tr>
                        <td class="text-center"><input name="subBox" type="checkbox" value="{$_data2.id}"></td>
                        <td>{$_data2.site_id}</td>
                        <td>{$_data2.purchaseorder_id}</td>
                        <td>{$_data2.id}</td>
                        <td>{$_data2.sku}</td>
                        <td>{$_data2.sku_name}</td>
                        <td>{$_data2.item}</td>
                        <td>{$_data2.transfer_hopper_name}</td>
                        <td>{$_data2.invoice_date}</td>
                        <td>{$data['users'][$_data2['check_man']]}</td>
                        <td>{$data['print_status'][$_data2['print_status']]}</td>
                        <td>{$_data2.pur_evidence}</td>
                    </tr>
                    <?php } ?>
                    </tbody>
                </table>
                <div class="fixed-table-toolbar">
                    <h3>
                        <a type="button" id="print_quality_report" target="_blank" class="btn  btn-success"
                           onclick="print_quality_report({$_data2.purchaseorder_id})">打印</a>
                    </h3>
                </div>
                <?php } ?>

                <div class="clearfix clear"></div>

                <div class="col-md-6 pull-left">
                    <label>每页 20 条记录,共 {$count} 项</label>
                </div>
                <div class="col-md-6">
                    <div class="page pull-right" style="padding: 0;margin: 0">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    /**
     * 打印当前采购单下选中的质检单,形成质检报告
     */
    function print_quality_report(purchaseorder_id) {
        var allChecked = new Array;
        $('input[name="subBox"]:checked').each(function (i) {
            allChecked[i] = $(this).val();
        });

        var check_ids = allChecked.join('-');
        if ('' == check_ids) {
            layer.msg('请正确选择质检单!',{'icon':'5'});
            return;
        }
        window.open("__URL__/print_quality_report?po_id=" + purchaseorder_id + "&ids=" + check_ids);
        setTimeout('window.location.reload()', 1000);

    }

    /**
     * 批量打印,打印所有选中的质检单,形成质检报告
     */
    function print_quality_reports() {
        var allChecked = new Array;
        $('input[name="subBox"]:checked').each(function (i) {
            allChecked[i] = $(this).val();
        });

        var check_ids = allChecked.join('-');
        if ('' == check_ids) {
            layer.msg('请正确选择质检单!',{'icon':'5'});
            return;
        }
        window.open("__URL__/print_quality_reports?ids=" + check_ids);
        setTimeout('window.location.reload()', 1000);
    }

    /**
     * 去掉字符串左右两侧的空格
     * @param str
     * @returns {void|string|XML}
     */
    function trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }
</script>
